//
//  ByBetRecordCell.m
//  caipiao_ios
//
//  Created by mc on 2018/8/6.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByBetRecordCell.h"



@implementation ByBetRecordCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByBetRecordCell";
    ByBetRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
        [self initViews];
    }
    return self;
}


- (void)initViews{
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    UIView *backgroundView = [[UIView alloc] init];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.top.equalTo(self.contentView).offset(10);
        make.bottom.equalTo(self.contentView).offset(0);
    }];
    backgroundView.layer.cornerRadius = 10;
    backgroundView.backgroundColor = [UIColor whiteColor];
    
    UIImageView *iconView = [[UIImageView alloc] init];
    [backgroundView addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(10);
        make.top.equalTo(backgroundView).offset(14);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
   
    
    
    UILabel *moneyLabel = [[UILabel alloc] init];
    [backgroundView addSubview:moneyLabel];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-37);
        make.top.equalTo(iconView.mas_top).offset(10);
        make.height.mas_equalTo(@15);
        make.width.mas_equalTo(@100);
    }];
    moneyLabel.text = @"投注100元";
    moneyLabel.font = FONT(13);
    moneyLabel.textColor = [UIColor blackColor];
    moneyLabel.textAlignment = NSTextAlignmentRight;
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconView.mas_right).offset(10);
        make.centerY.equalTo(iconView.mas_centerY).offset(0);
        make.height.mas_equalTo(@20);
        make.right.equalTo(moneyLabel.mas_left).offset(-10);
    }];
    titleLabel.text = @"未中奖";
    titleLabel.font = FONT(13);
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textAlignment = NSTextAlignmentLeft;
    
    UIImageView *arrowView = [[UIImageView alloc] init];
    [backgroundView addSubview:arrowView];
    [arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-16);
        make.centerY.equalTo(iconView.mas_centerY).offset(0);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    arrowView.image = [UIImage imageNamed:@"youjiantou1111"];
    
    
    UILabel *timeLabel = [[UILabel alloc] init];
    [backgroundView addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(moneyLabel.mas_left).offset(0);
        make.top.equalTo(moneyLabel.mas_bottom).offset(5);
        make.height.mas_equalTo(@15);
        make.right.equalTo(moneyLabel.mas_right).offset(0);
    }];
    timeLabel.text = @"2018-05-28";
    timeLabel.font = FONT(13);
    timeLabel.textColor = [UIColor lightGrayColor];
    timeLabel.textAlignment = NSTextAlignmentRight;
    
    self.iconView = iconView;
    self.moneyLabel = moneyLabel;
    self.titleLabel = titleLabel;
    self.timeLabel = timeLabel;
    
    
    ByDottedLineView *line = [[ByDottedLineView alloc] init];
    line.direction = DottedLineViewDirectionHorizontalFromRight;
    line.lineColor = BY_LINE_COLOR;
    line.lengthPattern = @[@4, @3];
    [backgroundView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.top.equalTo(iconView.mas_bottom).offset(12);
        make.height.mas_equalTo(@1);
    }];
    
    UILabel *endTimeLabel = [[UILabel alloc] init];
    [backgroundView addSubview:endTimeLabel];
    [endTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(15);
        make.bottom.equalTo(backgroundView).offset(-17);
        make.height.mas_equalTo(@15);
        make.right.equalTo(backgroundView).offset(-100);
    }];
    endTimeLabel.text = @"2018-05-28";
    endTimeLabel.font = FONT(14);
    endTimeLabel.textColor = [UIColor lightGrayColor];
    endTimeLabel.textAlignment = NSTextAlignmentLeft;
    endTimeLabel.hidden = YES;
    self.endTimeLabel = endTimeLabel;
    
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backgroundView addSubview:rightBtn];
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-10);
        make.bottom.equalTo(backgroundView).offset(-8);
        make.size.mas_equalTo(CGSizeMake(66, 27));
    }];
    rightBtn.backgroundColor = BY_THEME_COLOR;
    [rightBtn setTitle:@"继续投注" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.layer.cornerRadius = 9;
    rightBtn.titleLabel.font = FONT(11);
    [rightBtn addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
    self.rightBtn = rightBtn;
}


- (void)rightAction:(UIButton *)btn{
    if (self.rightBlock) {
        self.rightBlock();
    }
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:_netModel.logo] placeholderImage:DEFAULT_IMAGE];
    self.moneyLabel.text = [NSString stringWithFormat:@"投注%@元", _netModel.money];
    self.timeLabel.text = _netModel.time;
    if (_netModel.pay_status.integerValue == 0) {
        
        [self.rightBtn setTitle:@"支付" forState:UIControlStateNormal];
        self.titleLabel.text = @"未支付";
        self.endTimeLabel.hidden = NO;
        self.endTimeLabel.text = [NSString stringWithFormat:@"截止%@交易自动关闭", _netModel.end_time];
        
    }else if (_netModel.pay_status.integerValue == 1){
        
        [self.rightBtn setTitle:@"继续投注" forState:UIControlStateNormal];
        if (_netModel.is_prize.integerValue == 0) {
            self.titleLabel.text = @"未开奖";
        }else if (_netModel.is_prize.integerValue == 1){
            self.titleLabel.text = [NSString stringWithFormat:@"已中奖%.2f元",_netModel.prize_money.floatValue];
        }else if (_netModel.is_prize.integerValue == 2){
            self.titleLabel.text = @"未中奖";
        }
    }else if (_netModel.pay_status.integerValue == 2){
        self.titleLabel.text = @"交易关闭";
        [self.rightBtn setTitle:@"继续投注" forState:UIControlStateNormal];
    }
    
    
    if (_netModel.is_prize.integerValue == 1){
        self.titleLabel.text = [NSString stringWithFormat:@"已中奖%.2f元",_netModel.prize_money.floatValue];
    }else {
        self.titleLabel.text = _netModel.status;
    }
    
}


@end
